package com.victor.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.victor.entity.Banner;
import com.victor.service.BannerService;
import com.victor.utils.Msg;

/**
 * banner管理
 * 
 * @author qinyuquan
 *
 */
@RestController
@RequestMapping("/banner")
public class BannerController {

	@Autowired
	private BannerService service;
	
	/**
	 * 添加banner
	 * @param banner
	 * @return
	 */
	@RequestMapping("/insert")
	public Msg insert(Banner banner) {
		if (banner == null || banner.getBannerpath()==null || banner.getProvince()==null || banner.getCity()==null) {
			return Msg.fail("参数错误");
		}
		boolean b = service.insert(banner);
		return Msg.judge(b);
	}

	
	/**
	 * 修改banner信息
	 * @param banner
	 * @return
	 */
	@RequestMapping("/update")
	public Msg update(Banner banner) {
		if (banner==null || null==banner.getId()) {
			return Msg.fail("参数错误");
		}
		boolean b = service.update(banner);
		return Msg.judge(b);
	}


	/**
	 * 根据id，批量删除
	 * @param ids
	 * @return
	 */
	@RequestMapping("/batchDelete")
	public Msg batchDelete(int[] ids) {
		if (ids==null || ids.length==0) {
			return Msg.fail("参数错误");
		}
		boolean b = service.batchDelete(ids);
		if (b) {
			return Msg.success();
		}
		return Msg.fail();
	}


	/*
	 * 查询所有banner
	 */
	@RequestMapping("/selectAll")
	public Msg selectAll() {
		List<Banner> listBanner = service.selectAll();
		return Msg.success().add("listBanner", listBanner);
	}
	
	
	
	/*
	 * app查询bannerr
	 */
	@RequestMapping("/selecByPara")
	public Msg selecByPara(Banner banner) {
		if (banner == null) {
			return Msg.fail("入参错误");
		}
		List<Banner> listBanner = service.selecByPara(banner);
		return Msg.success().add("listBanner", listBanner);
	}
	
}
